<?php

function fnmatch2($pattern, $string) {
	for ($op = 0, $npattern = '', $n = 0, $l = strlen($pattern); $n < $l; $n++) {
		switch ($c = $pattern[$n]) {
			case '\\':
				$npattern .= '\\' . @$pattern[++$n];
				break;
			case '.': case '+': case '^': case '$': case '(': case ')': case '{': case '}': case '=': case '!': case '<': case '>': case '|':
				$npattern .= '\\' . $c;
				break;
			case '?': case '*':
				$npattern .= '.' . $c;
				break;
			case '[': case ']': default:
				$npattern .= $c;
				if ($c == '[') {
					$op++;
				} else if ($c == ']') {
					if ($op == 0) return false;
					$op--;
				}
				break;
		}
	}

	if ($op != 0) return false;

	return preg_match('/' . $npattern . '/i', $string);
}

$string = "20092020_123456.jpg";
$pattern = "2010";

$result = fnmatch2($pattern, $string);
echo "".$result;
?>